import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

file_path = r"D:\python charm\01\可视化\销售看板参考\销售明细_12.xlsx"
df12 = pd.read_excel(file_path)

# 统计各区域数量
region_counts = df12['区域'].value_counts()

# 指定区域的顺序
region_order = ['华北', '华南', '东北', '西北', '西南', '华东']
region_counts = region_counts.reindex(region_order)

# 创建图表
plt.figure(figsize=(8, 4), facecolor='#2E4057')
ax = plt.gca()
ax.set_facecolor('#2E4057')

# 绘制柱状图
bars = plt.bar(region_counts.index, region_counts.values, color='#6DCFF6', width=0.6)

# 添加数据标签
for bar in bars:
    plt.text(
        bar.get_x() + bar.get_width() / 2,
        bar.get_height() + 1,
        f"{int(bar.get_height())}",
        ha='center', va='bottom', fontsize=20, color='white'
    )

# 设置标题和标签
plt.title("区域销量", fontsize=20, color='white', pad=20)
plt.xticks(fontsize=22, color='white')
plt.yticks([])
plt.tick_params(axis='x', which='both', length=0)

# 隐藏图表边框
for spine in ax.spines.values():
    spine.set_visible(False)

# 调整布局
plt.tight_layout()

plt.savefig(r'D:\python charm\01\可视化\销售看板参考\图片\各区域销量.png')

plt.show()